import axios from "axios";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

//创建实例对象
let instance = axios.create({
	baseURL: "http://localhost:4000",
});

//配置请求拦截器
instance.interceptors.request.use((config) => {
	//展示进度条
	NProgress.start();
	// 必须返回config
	return config;
});

// 配置响应拦截器 参数(成功,失败)
instance.interceptors.response.use((response) => {
	//关闭进度条
	NProgress.done();
	return response.data;
}, error => {
	console.log('请求失败')
	console.log(error)
	// 必须返回一个pending状态的promise()
	return new Promise(()=>{})
});

export default instance;
